﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Reflection;

namespace CRM.Cache
{
    public class CacheFactory
    {
        static readonly string path = ConfigurationManager.AppSettings["DALCache"];

        static ICache createInstance = null;

        private CacheFactory()
        {

        }

        //使用单例缓存，防止多次反射加载
        public static ICache CreateInstance()
        {
            if (createInstance == null)
                createInstance = new CacheFactory().CreateCache();
            return createInstance;
        }

        public ICache CreateCache()
        {
             var full = path.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            var assembly = full[0];

            var className = full[1];

            return (ICache)Assembly.Load(assembly).CreateInstance(className);

        }
    }
}
